Giter VIP home page Giter VIP logo

Comments (4)

christopherseeley avatar christopherseeley commented on May 11, 2024

Since you're not using the ads.properties file, you'll need to explicitly set your application name and network code for the Session. See withApplicationName and withNetworkCode.

I'll leave this issue open until the example is updated.

from googleads-java-lib.

plammy avatar plammy commented on May 11, 2024

I use this file https://github.com/googleads/googleads-java-lib/blob/1.36.0/examples/dfp_axis/src/main/java/dfp/axis/auth/CreateDfpSessionWithoutPropertiesFile.java and I try to modify this part

// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfp.axis.auth;

import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
import com.google.api.ads.common.lib.exception.OAuthException;
import com.google.api.ads.common.lib.exception.ValidationException;
import com.google.api.ads.dfp.axis.factory.DfpServices;
import com.google.api.ads.dfp.axis.v201311.Network;
import com.google.api.ads.dfp.axis.v201311.NetworkServiceInterface;
import com.google.api.ads.dfp.lib.client.DfpSession;
import com.google.api.client.auth.oauth2.Credential;

/**

  • This example demonstrates how to create a Credential and an DfpSession

  • object without using an ads.properties file.
    *

  • @author Ray Tsang
    */
    public class CreateDfpSessionWithoutPropertiesFile {

    private static final String CLIENT_ID = "15xxxxxxxnt.com";
    private static final String CLIENT_SECRET = "zQnEloxxxxxxxxxx60";
    private static final String REFRESH_TOKEN = "1/OMxxxxxxx8OkM-unR30zcRFq6";
    private static final String APPLICATION_NAME = "test";

    private static DfpSession createDfpSession(String clientId, String clientSecret,
    String refreshToken, String applicationName) throws OAuthException,
    ValidationException {
    // Create a valid OAuth 2.0 credential without using a properties file.
    Credential credential = new OfflineCredentials.Builder()
    .forApi(Api.DFP)
    .withClientSecrets(clientId, clientSecret)
    .withRefreshToken(refreshToken)
    .build()
    .generateCredential();

    // Create a new DfpSession without using a properties file.
    return new DfpSession.Builder()
    .withApplicationName(applicationName)
    .withOAuth2Credential(credential)
    .build();
    }

    public static void runExample(DfpServices dfpServices, DfpSession dfpSession)
    throws Exception {
    // Get the NetworkService.
    NetworkServiceInterface networkService =
    dfpServices.get(dfpSession, NetworkServiceInterface.class);

    // Gets the current network.
    Network network = networkService.getCurrentNetwork();

    System.out.printf("Current network has network code "%s" and display name "%s".\n",
    network.getNetworkCode(), network.getDisplayName());
    }

    public static void main(String[] args) throws Exception {
    if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE")
    || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
    throw new IllegalArgumentException("Please input your client IDs or secret. "
    + "See https://console.developers.google.com/project");
    }

    if (REFRESH_TOKEN.equals("INSERT_REFRESH_TOKEN_HERE")) {
    throw new IllegalArgumentException(
    "Please input your refresh token. See GetRefreshTokenWithoutPropertiesFile.java.");
    }

    // Create an DfpSession without using a properties file.
    DfpSession dfpSession = createDfpSession(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN, APPLICATION_NAME);
    DfpServices dfpServices = new DfpServices();

    runExample(dfpServices, dfpSession);
    }
    }

But it still through exception:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection timed out: connect
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:649)
at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:409)
at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:88)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:92)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)

Kind regards
PM

from googleads-java-lib.

christopherseeley avatar christopherseeley commented on May 11, 2024

Can you please start a new thread in the DFP API forum? That's a more appropriate channel for support than the issue tracker.

from googleads-java-lib.

jradcliff avatar jradcliff commented on May 11, 2024

Closing per the previous comment.

from googleads-java-lib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.